package ca.usherbrooke.domus.sipnmove2.model.communication.impl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * Handle a socket communication between two parties
 */
public class SocketClientCommunication extends AbstractSocketCommunication {

	/**
	 * IP address to call
	 */
	private String ipAddress;
	
	/**
	 * Port to use
	 */
	private Integer port;

	/**
	 * Default constructor
	 * @param ipAddress IP address
	 * @param port Port
	 */
	public SocketClientCommunication(String ipAddress, Integer port) {
		
		this.ipAddress = ipAddress;
		this.port = port;
		
	}

	@Override
	public void initialize() {

		try {
			socket = new Socket(ipAddress, port);

			outputBuffer = new PrintWriter(socket.getOutputStream(), true);
			inputBuffer = new BufferedReader(new InputStreamReader(socket.getInputStream()));

		} catch (UnknownHostException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
